package persistency.writer;

import java.util.Collection;

import model.Course;
import model.Teacher;
import settings.PathSettings;

public class TeacherWriter extends ContainerWriter {

	private IntersectionWriter tcpw = new TeacherCoursePreferenceWriter();
	
	/** Instantiate the TeacherWriter */
	public TeacherWriter() {
		super(PathSettings.TEACHERFILE, "#Code\tName\tAmountWantedHours\n");
	}
	
	/** Writes a teacher object together with the teacher's course preferences */
	@Override
	public void write(Writable writable) {
		super.write(writable);
		Teacher teacher = (Teacher)writable;
		Collection<Course> coursePreferences = teacher.getCoursePreferences();
		tcpw.write(writable.getPrimaryKey(), coursePreferences);
	}
	
	/**
	 * Inner class that deals with the intersection of Teacher and courseCode
	 * @author Wim
	 */
	private class TeacherCoursePreferenceWriter extends IntersectionWriter {

		public TeacherCoursePreferenceWriter(){
			super(PathSettings.TEACHERCOURSEPREFERENCEFILE,"#TeacherCode\tCourseCode\n");
		}
	}
	
	@Override
	public void close(){
		super.close();
		tcpw.close();
	}
}
